package com.itedge.solutionmanager.web.convert;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;

import com.itedge.infrastructure.service.domain.IEntityService;
import com.itedge.solutionmanager.domain.impl.Customer;

/**
 * Converter to convert String values (IDs) to Customer objects with help of Customer service
 * 
 * @author Jan
 *
 */
public class StringToCustomerConverter implements Converter<String, Customer> {

	@Autowired
	private IEntityService<Customer> customerService;
	
	@Override
	public Customer convert(String source) {
		if (StringUtils.isEmpty(source)) {
			//throw new IllegalArgumentException("ID for customer object cannot be empty or null!");
			return null;
		}
		return customerService.findEntity(Long.parseLong(source));
	}

}
